﻿@model Orchard.Comments.ViewModels.CommentsDetailsViewModel
@using Orchard.Comments.Models;
@using Orchard.Comments.ViewModels;

@{ Layout.Title = T("Comments for {0}", Model.DisplayNameForCommentedItem).ToString(); }

<div class="manage">
    @if (Model.CommentsClosedOnItem) {
        using (Html.BeginFormAntiForgeryPost(Url.Action("Enable", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) {
    <fieldset>
        <button type="submit" title="@T("Enable Comments")">@T("Enable Comments")</button>
    </fieldset>
        }
    } else {
        using (Html.BeginFormAntiForgeryPost(Url.Action("Disable", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) { 
    <fieldset>
        <button type="submit" class="primaryAction" title="@T("Disable Comments")">@T("Disable Comments")</button>
    </fieldset>
        }
    } 
</div>
@using(Html.BeginFormAntiForgeryPost()) { 
    @Html.ValidationSummary()
    <fieldset class="bulk-actions">
        <label for="publishActions">@T("Actions:")</label>
        <select id="publishActions" name="@Html.NameOf(m => m.Options.BulkAction)">
            @Html.SelectOption(Model.Options.BulkAction, CommentDetailsBulkAction.None, T("Choose action...").ToString())
            @Html.SelectOption(Model.Options.BulkAction, CommentDetailsBulkAction.Approve, T("Approve").ToString())
            @Html.SelectOption(Model.Options.BulkAction, CommentDetailsBulkAction.Unapprove, T("Unapprove").ToString())
            @Html.SelectOption(Model.Options.BulkAction, CommentDetailsBulkAction.MarkAsSpam, T("Mark as Spam").ToString())
            @Html.SelectOption(Model.Options.BulkAction, CommentDetailsBulkAction.Delete, T("Delete").ToString())
        </select>
        <button type="submit" name="submit.BulkEdit" value="@T("Apply")">@T("Apply")</button>
    </fieldset>
    <fieldset class="bulk-actions">
        <label for="filterResults">@T("Filter:")</label>
        <select id="filterResults" name="@Html.NameOf(m => m.Options.Filter)">
            @Html.SelectOption(Model.Options.Filter, CommentDetailsFilter.All, T("All Comments").ToString())
            @Html.SelectOption(Model.Options.Filter, CommentDetailsFilter.Approved, T("Approved Comments").ToString())
            @Html.SelectOption(Model.Options.Filter, CommentDetailsFilter.Pending, T("Pending Comments").ToString())
            @Html.SelectOption(Model.Options.Filter, CommentDetailsFilter.Spam, T("Spam").ToString())
        </select>
        <button type="submit" name="submit.Filter" value="@T("Apply")">@T("Apply")</button>
    </fieldset>
    <fieldset>
        <table class="items" summary="@T("This is a table of the comments for the content item")">
            <colgroup>
                <col id="Col1" />
                <col id="Col2" />
                <col id="Col3" />
                <col id="Col4" />
                <col id="Col5" />
                <col id="Col6" />
            </colgroup>
            <thead>
                <tr>
                    <th scope="col">&nbsp;&darr;</th>
                    <th scope="col">@T("Status")</th>
                    <th scope="col">@T("Author")</th>
                    <th scope="col">@T("Comment")</th>
                    <th scope="col">@T("Date")</th>
                    <th scope="col"></th>
                </tr>
            </thead>
            @{var commentIndex = 0;}
            @foreach (var commentEntry in Model.Comments) {
            <tr>
                <td>
                    <input type="hidden" value="@Model.Comments[commentIndex].Comment.Id" name="@Html.NameOf(m => m.Comments[commentIndex].Comment.Id)"/>
                    <input type="checkbox" value="true" name="@Html.NameOf(m => m.Comments[commentIndex].IsChecked)"/>
                    <input type="hidden" value="@Model.DisplayNameForCommentedItem" name="DisplayNameForCommentedtem" />
                    <input type="hidden" value="@Model.CommentedItemId" name="CommentedItemId" />
                </td>
                <td>
                    @if (commentEntry.Comment.Status == CommentStatus.Spam) { @T("Spam"); }
                    else if (commentEntry.Comment.Status == CommentStatus.Pending) { @T("Pending"); }
                    else { @T("Approved"); }
                </td>
                <td>@commentEntry.Comment.Author</td>
                <td>
                @if (commentEntry.Comment.CommentText != null) {
                    var text = commentEntry.Comment.CommentText.Length > 23 ? commentEntry.Comment.CommentText.Substring(0, 24) : (commentEntry.Comment.CommentText + T(" ..."));
                    @text
                } 
                </td>
                <td>@Display.DateTime(DateTimeUtc: commentEntry.Comment.CommentDateUtc.GetValueOrDefault())</td>
                <td>
                    <ul class="actions">
                        <li class="construct">
                            <a href="@Url.Action("Edit", new {commentEntry.Comment.Id})" title="@T("Edit Comment")">@T("Edit")</a>
                        </li>
                        <li class="destruct"></li>
                    </ul>
                </td>
            </tr>
            commentIndex = commentIndex + 1;
            } 
        </table>
    </fieldset>
} 
<div class="manage">
    @if (Model.CommentsClosedOnItem) {
        using (Html.BeginFormAntiForgeryPost(Url.Action("Enable", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) 
        { 
    <fieldset>
        <button type="submit" title="@T("Enable Comments")">@T("Enable Comments")</button>
    </fieldset>
        }
    } else {
        using (Html.BeginFormAntiForgeryPost(Url.Action("Disable", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) { 
    <fieldset>
        <button type="submit" class="primaryAction" title="@T("Disable Comments")">@T("Disable Comments")</button>
    </fieldset>
        }
    } 
</div>